Skip to content

feat: implement PriceCalculator rule for Epic 5.4#145

Merged
mcj-coder merged 9 commits into
mainfrom
feature/43-price-calculator-rule
Jan 19, 2026
Merged

feat: implement PriceCalculator rule for Epic 5.4#145
mcj-coder merged 9 commits into
mainfrom
feature/43-price-calculator-rule

Conversation

@martincjarvis

@martincjarvis martincjarvis commented Jan 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements the PriceCalculator rule that calculates item prices based on:

  • Base price (from item/recipe definition)
  • Quality multipliers (6 tiers matching GDD crafting system)
  • Supply/demand modifiers (basic settlement-level adjustment)

Formula: Final Price = Base Price × Quality Multiplier × Supply/Demand Multiplier

Issue

Closes #43

Changes

  • Added PriceCalculator static class with pure functions in FantasyRpgWorld.Simulation/Rules/PriceCalculator.cs
  • Implements quality multipliers for 6 tiers: Crude (0.5x), Common (1.0x), Quality (1.5x), Fine (2.0x), Superior (3.0x), Masterwork (5.0x)
  • Implements supply/demand modifiers: Abundant (0.7x), Normal (1.0x), Scarce (1.5x)
  • Returns Currency value object for type safety
  • Includes standard rounding for copper amounts
  • Added comprehensive test suite in PriceCalculatorTests.cs covering quality multipliers, supply/demand modifiers, combined scenarios, edge cases, and rounding behavior
  • Created design and implementation plan documents

Testing

  • Tests added/updated
  • Manual testing done

All tests passing:

CI Build & Test: PASSED
Total tests: 595
Result: ✓ (see https://github.com/mcj-coder-org/fantasy-rpg-world/actions/runs/21151285413/job/60827661937)

Detailed TDD plan with 6 tasks:
- Task 1: Quality multiplier tests (6 tiers)
- Task 2: Supply/demand modifier tests
- Task 3: Combined modifiers tests
- Task 4: Edge case tests
- Task 5: Rounding behavior tests
- Task 6: Full verification

Expected: 22 tests total

Refs #43
Implements 6-tier quality multiplier system from GDD:
- Crude (0-20): 0.5x
- Common (21-40): 1.0x
- Quality (41-60): 1.5x
- Fine (61-80): 2.0x
- Superior (81-99): 3.0x
- Masterwork (100+): 5.0x

Refs #43
Tests verify 4 market conditions:
- Abundant (0.5x)
- Normal (1.0x)
- Scarce (1.5x)
- Very Rare (2.0x)

Refs #43
Tests verify realistic pricing with both quality and supply/demand:
- Fine quality + scarce market
- Crude quality + abundant market
- Masterwork + abundant market

Refs #43
Tests verify boundary conditions and error handling:
- Quality at 0 and > 100
- Zero base price
- Negative quality (throws exception)
- Zero/negative supply/demand (throws exception)

Refs #43
Tests verify:
- Fractional copper amounts round correctly
- Large values don't overflow
- Standard Math.Round() behavior

Refs #43
@github-actions

github-actions Bot commented Jan 19, 2026

Copy link
Copy Markdown
Messages
📖 ✅ Issue properly linked: Closes #43
📖 ✅ Summary section found
📖 ✅ PR title follows Conventional Commits format
📖

📝 New plan documents created: docs/plans/2026-01-19-price-calculator-design.md, docs/plans/2026-01-19-price-calculator-implementation.md

Recommended Persona Reviews

💻 .NET Specialist - C# code changes detected

See docs/roles/ for persona details.


Danger analysis complete for feat: implement PriceCalculator rule for Epic 5.4. 6 files changed, 9 commits.

Generated by 🚫 dangerJS against ca3b982

@mcj-coder mcj-coder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review - Approved

Reviewed as .NET 10 Specialist persona.

Summary

Status: APPROVED

This is high-quality .NET code that demonstrates excellent craftsmanship. The implementation is production-ready, well-tested, and follows all established patterns. All 22 tests pass, CI checks are green.

Strengths

Pattern Consistency - Perfectly matches XpCalculator and CraftingOutcomeRule patterns
Type Safety - Excellent use of Currency value object for type-safe price handling
Validation - Comprehensive input validation with clear error messages
Modern C# - Clean switch expressions and appropriate use of C# 14 features
Mathematical Correctness - Proper use of decimal for calculations, Math.Round() for rounding
Test Quality - 22 comprehensive tests covering all scenarios (quality tiers, supply/demand, edge cases, rounding)
Documentation - Clear XML docs and inline comments

Minor Notes (Non-Blocking)

  • Minor path discrepancy in PR description (references FantasyRpgWorld.Simulation/Rules/ but actual path is FantasyRpgWorld.Core/Rules/)
  • Rounding mode uses default banker's rounding (ToEven) vs XpCalculator's AwayFromZero - both are valid, but could consider explicit mode for clarity

These are documentation notes only and do not affect code quality.

Technical Assessment

Criterion Rating
C# Best Practices ⭐⭐⭐⭐⭐ Excellent
.NET 10 Compatibility ⭐⭐⭐⭐⭐ Excellent
Type Safety ⭐⭐⭐⭐⭐ Excellent
Test Coverage ⭐⭐⭐⭐⭐ Excellent
Pattern Consistency ⭐⭐⭐⭐⭐ Excellent

Conclusion

Production-ready code. Ready to merge.

Reviewed by: Martin Jarvis (Tech Lead)

@mcj-coder
mcj-coder merged commit a5aa8d8 into main Jan 19, 2026
3 checks passed
@mcj-coder
mcj-coder deleted the feature/43-price-calculator-rule branch January 19, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5.4 Implement PriceCalculator rule

2 participants